<%@ page language="java" contentType="text/html;charset=UTF-8"
   	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript" src="jquery/jquery.js"></script>
<script type='text/javascript' src='jquery/jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {

	function log(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}

	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}

	$("#txtusername").focus().autocomplete(["${usernames}"]);

});
</script>
<html>
<form autocomplete="off" name="frmuser" action="add_accessible_user.html" method="post">
<table cellpadding="0" cellspacing="0" width="700" align="center" border="0" style="color: #333;">
	<tr><td colspan="3" align="center" style="font-size: 13px;" valign="top"><u>ចែករំលែកឯកសារ</u></td></tr>
	<tr><td colspan="3" height="10"><input type="hidden" name="txtfileid1" id="txtfileid1" value="${fileid}" /></td></tr>
	<tr>
		<td colspan="3" height="8" align="left">
		<p align="left"​ style="line-height:20px;">សូមបញ្ចូលឈ្មោះគណនី ឬ ក្រុមដែលអ្នកចង់ចែករំលែកឯកសារនេះអោយ។  ករណីអ្នកមិនបានបញ្ចូលនោះទេ  ឯកសារនេះនឹងត្រូវ ចែករំលែកជាសាធារណះ។</p>
		ឈ្មោះគណនី:&nbsp;<input type="text" id="txtusername" name="txtusername">&nbsp;<input type="submit" class="input_button" value="បញ្ចូល" name="btnuser">
		<c:if test="${fn:length(error_msg1)>0}">
				<br><br><div style="color: red;"><c:out value="${error_msg1}"></c:out></div>
		</c:if>
		</td>
	</tr>
	<c:if test="${fn:length(users)>0}">
	<tr><td colspan="3" height="10"> </td></tr>
	<tr class="mygroupheader" align="center" >
		<td width="6%"​ height="25">លេខរៀង</td>	
		<td width="30%">ឈ្មោះគណនី</td>		
		<td width="10%">លុបចោល</td>
	</tr>
	<%
		String usercolor="#EEE";
	%>
	<c:forEach var="x" begin="0" end="${fn:length(users)-1}" step="1" varStatus ="status">
		<%
			String fileStatus="";
			usercolor=(usercolor=="#EEE")?"#FFF":"#EEE";
		%>
	<c:if test="${ownerid==users[x].USER_ID}">
		<%
			fileStatus="- File Owner";
		%>
	</c:if>
			<tr bgcolor="<%=usercolor%>" align="center">
				<td height="30" style="border-left:solid 1px #DDD; border-bottom:solid 1px #DDD;"><c:out value="${x+1}"/></td>
				<td align="center" style="border-left:solid 1px #DDD; border-bottom:solid 1px #DDD;">&nbsp;<c:out value="${users[x].USER_NAME}"/><span style="color: #444;font-size: 9px;">&nbsp;&nbsp;<%=fileStatus%></span></td>
				<td style="border:solid 1px #DDD; border-top:solid 0px #DDD;">
				<c:if test="${ownerid!=users[x].USER_ID}">
					<img src="images/remove.png" width="16" height="16" onclick="deleteFileUser(${fileid},${users[x].USER_ID})" style="cursor: pointer;">
				</c:if>
				</td>
			</tr>
	</c:forEach>
	</c:if>
</table>
</form >
<br><br>
<form autocomplete="off" name="frmgroup" action="add_accessible_group.html" method="post">
<table cellpadding="0" cellspacing="0" width="700" align="center" border="0">
	<c:if test="${fn:length(mygroups)>0}">
		<tr><td colspan="3" height="10"><input type="hidden" name="txtfileid2" id="txtfileid2" value="${fileid}" /></td></tr>
		<tr>
			<td colspan="3" height="8" align="left">
			ឈ្មោះក្រុម:&nbsp;&nbsp;&nbsp;
			<select name="txtgroup" id="txtgroup">
					<c:forEach var="i" begin="0" end="${fn:length(mygroups)-1}" step="1" varStatus="status">
						<option value="${mygroups[i].GROUP_ID}"><c:out value="${mygroups[i].GROUP_NAME}"></c:out></option>
					</c:forEach>
			</select>
			
			&nbsp;<input type="submit" value="បញ្ចូល" class="input_button" name="btngroup"​>
			<c:if test="${fn:length(error_msg2)>0}">
					<br><br><div style="color: red;"><c:out value="${error_msg2}"></c:out></div>
			</c:if>
			</td>
		</tr>
		
		<c:if test="${fn:length(groups)>0}">
		<tr><td colspan="3" height="10"> </td></tr>
		<tr class="mygroupheader" align="center" >
			<td width="6%" height="25">លេខរៀង</td>	
			<td width="30%">ឈ្មោះក្រុម</td>		
			<td width="10%">លុបចោល</td>
		</tr>
		<%
			String grpcolor="#EEE";
		%>
		<c:forEach var="x" begin="0" end="${fn:length(groups)-1}" step="1" varStatus ="status">
			<%
			grpcolor=(grpcolor=="#EEE")?"#FFF":"#EEE";
			%>
				<tr bgcolor="<%=grpcolor%>" align="center">
					<td height="30" style="border-left:solid 1px #DDD; border-bottom:solid 1px #DDD;"><c:out value="${x+1}"/></td>
					<td align="center" style="border-left:solid 1px #DDD; border-bottom:solid 1px #DDD;">&nbsp;<c:out value="${groups[x].GROUP_NAME}"/></td>
					<td style="border:solid 1px #DDD; border-top:solid 0px #DDD;"><img src="images/remove.png" width="16" height="16" onclick="deleteFileGroup(${fileid},${groups[x].GROUP_ID})" style="cursor: pointer;"></td>
				</tr>
		</c:forEach>
		</c:if>
		<tr>
			<td colspan="3" height="20"> </td>
		</tr>

	</c:if>
	<c:if test="${fn:length(mygroups)<=0}">
		<tr><td colspan="3" height="10"><input type="hidden" name="txtfileid2" id="txtfileid2" value="${fileid}" /></td></tr>
		<tr>
			<td colspan="3" height="8" align="left">
			
			</td>
		</tr>
	</c:if>
	<tr>
			<td colspan="3" height="8" align="center">
				<a href="myuploads.html">ត្រលប់ទៅកាន់ទំព័រឯកសាររបស់ខ្ញុំ</a>
			</td>
	</tr>
</table>

</form>
<br><br>
</html>